<admintpl file="header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
    	<li><a href="{:U('Admin/Special/specialAdd',array('news_id'=>$special_id,$id_type=>$id_val))}">编辑专题</a></li>
    	<li class="active"><a href="{:U('Admin/Special/special_column_index',array('special_id'=>$special_id,$id_type=>$id_val))}">专题分栏</a></li>
        <li ><a href="{:U('Admin/Special/index',array('news_id'=>$special_id,'special_id'=>0,$id_type=>$id_val))}">文章管理</a></li>
    </ul>
    <form class="js-ajax-form" action="" method="post">
    	 <div>
    		<a href="#" onclick="addColumnType('{$special_id}');" class="btn btn-primary" >添加</a>&nbsp;&nbsp;
    	</div>
    	
        <br/><br/>
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th>序号</th>
                <th>类型名称</th>
                <th>权重</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <foreach name="data" item="vo" key="keys">
                <tr>
                    <td>{$keys}</td>
                    <td><input type="text" name="type_name" id="type_name_{$vo.type_id}" value="{$vo.name}" disabled="disabled" size="4"  class="input_edit">
                        <a id="edit_name_{$vo.type_id}" href='javascript:void(0);' onclick="update_weight('{$vo.type_id}','name')" class="edit_sub">修改</a>
                        <input type="hidden" name="old_name" id="old_name_{$vo.news_id}" value="{$vo.name}"></td>
                    <td><input type="text" name="weight" id="weight{$vo.type_id}" value="{$vo.weight}" disabled="disabled" size="4"  class="input_edit">
                        <a id="edit_weight_{$vo.type_id}" href='javascript:void(0);' onclick="update_weight('{$vo.type_id}','weight')" class="edit_sub">修改</a>
                        <input type="hidden" name="old_weight" id="old_weight_{$vo.type_id}" value="{$vo.weight}">
                    </td>
                    <td><a href='{:U("Admin/Special/special_column_del",array("type_id"=>$vo["type_id"]))}' class="js-ajax-dialog-btn"
                           data-msg="确定要删除此类型吗？">删除</a></td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </form>
    <div class="pagination">{$page}</div>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
    function update_weight(type_id,type){
        if(type == 'weight'){
            edit_column = $("#edit_weight_"+type_id).html();
            column_befor = $("#old_weight_"+type_id).val();//原权重值
            column  = $("#weight"+type_id).val(); //现权重值
            now_input_type = $("#weight" + type_id); //权重 ID
            now_edit_type  = $("#edit_weight_" + type_id);  //修改 按钮ID
        }else if(type == 'name'){
            edit_column = $("#edit_name_"+type_id).html();
            column_befor = $("#old_name_"+type_id).val();//原名称值
            column  = $("#type_name_"+type_id).val(); //现名称值
            now_input_type = $("#type_name_" + type_id); //名称 ID
            now_edit_type  = $("#edit_name_" + type_id);  //修改 按钮ID
        }

        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == name){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                if(type == 'name'){
                    var flag = false;
                    $.ajax({
                        type:"post",
                        async:false,
                        url:"./index.php?g=admin&m=Movement&a=filter_words",
                        data:'data='+column,
                        dataType:"text",
                        success:function(data){
                            if(data){
                                if(confirm('您编辑的内容涉及敏感词'+data+'是否继续操作')){
                                    flag= true;
                                    return true;
                                }else{
                                    flag= false;
                                    return false;
                                }
                            }else{
                                flag = true;
                                return true;
                            }
                        }
                    });
                    if(flag == false){
                        return flag;
                    }
                }
                $.post("{:U('Special/editColumnType')}", {type: type, type_id: type_id, val: column},
                        function (result) {
                            if (result == 1) {
                                now_input_type.attr("disabled", "disabled");
                                now_edit_type.html("修改");
                                location.reload()
                            }else{
                                alert("异常!")
                            }
                        }
                );
            }
        }
    }

    function addColumnType(special_id){
        layer.open({
            type: 2,
            //skin: 'layui-layer-lan',
            title: '添加专题分栏',
            fix: false,
            shadeClose: true,
            maxmin: true,
            area: ['1000px', '500px'],
//            content: "<?php echo U('Admin/Special/addType')?>"+'&special_id='+special_id,
//            content: "<?php if($_SERVER['SERVER_NAME'] == 'fzadmin.xinhuiwen.com') { echo U('Admin/Special/addType')?>"+'?special_id='+special_id+"<?php ;}else{echo U('Admin/Special/addType')?>"+'&special_id='+special_id+"<?php ;}?>",
               content: "<?php echo U('Admin/Special/addType')?>"+'&special_id='+special_id+"<?php ;?>",
		end: function(){
                location.reload();
            }
        });
    }
//    function refresh_news(news_id){
//        $.post("<?php echo U('Admin/NewsManage/refreshNews')?>",{news_id:news_id}, function(result){
//            if(result == '1'){
//                var msg = '刷新成功';
//            }else{
//                var msg = '刷新失败';
//            }
//
//            alert(msg);
//            window.location.reload();
//        });
//    }
//    $(document).ready(function () {
//
//        $('input[name="query_form_btn"]').click(function () {
//            $('#query_form').attr('action', $(this).attr('data-action'));
//            $('#query_form').submit();
//        });
//        $("#category").val("{$formParam.categoryId}");
//
//
//    });

</script>
</body>
</html>